package com.dxb.test.thread;

public class 死锁 {
    private Object lock1 = new Object();
    private Object lock2 = new Object();

    public static void main(String[] args) {
        死锁 锁 = new 死锁();
        new Thread(() -> {
            synchronized (锁.lock1) {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (锁.lock2) {
                    System.out.println("线程1..。。。。。。");
                }
            }
        }, "lock1-lock2").start();
        new Thread(() -> {
            synchronized (锁.lock2) {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (锁.lock1) {
                    System.out.println("线程2..。。。。。。");
                }
            }
        }, "lock2-lock1").start();
    }

}
